package org.jarraiders.musiclibrary.client.view;

import org.jarraiders.musiclibrary.client.presenter.EditAlbumPresenter;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class EditAlbumView extends Composite implements EditAlbumPresenter.Display{
	private final TextBox albumName;
	  private final TextBox albumYear;	  
	  private final FlexTable detailsTable;
	  private final Button saveButton;
	  private final Button cancelButton;
	  
	  public EditAlbumView() {
		    DecoratorPanel contentDetailsDecorator = new DecoratorPanel();
		    contentDetailsDecorator.setWidth("18em");
		    initWidget(contentDetailsDecorator);

		    VerticalPanel contentDetailsPanel = new VerticalPanel();
		    contentDetailsPanel.setWidth("100%");

		    // Create the contacts list
		    //
		    detailsTable = new FlexTable();
		    detailsTable.setCellSpacing(0);
		    detailsTable.setWidth("100%");
		    detailsTable.addStyleName("contacts-ListContainer");
		    detailsTable.getColumnFormatter().addStyleName(1, "add-contact-input");
		    albumName = new TextBox();		    
		    albumYear = new TextBox();
		    
		    initDetailsTable();
		    contentDetailsPanel.add(detailsTable);
		    
		    HorizontalPanel menuPanel = new HorizontalPanel();
		    saveButton = new Button("Save");
		    cancelButton = new Button("Cancel");
		    menuPanel.add(saveButton);
		    menuPanel.add(cancelButton);
		    contentDetailsPanel.add(menuPanel);
		    contentDetailsDecorator.add(contentDetailsPanel);
		  }
	  private void initDetailsTable() {
		    detailsTable.setWidget(0, 0, new Label("Album name"));
		    detailsTable.setWidget(0, 1, albumName);
		    detailsTable.setWidget(1, 0, new Label("Year"));
		    detailsTable.setWidget(1, 1, albumYear);
		    
		    albumName.setFocus(true);
		  }
	  

		  public HasClickHandlers getSaveButton() {
		    return saveButton;
		  }
		  
		  public HasClickHandlers getCancelButton() {
		    return cancelButton;
		  }
		  
		  public Widget asWidget() {
		    return this;
		  }
		@Override
		public HasValue<String> getAlbumName() {
			
			return albumName;
		}
		@Override
		public HasValue<String> getAlbumYear() {
			
			return albumYear;
		}
}
